package com.alogic.xscript.log;

import com.anysoft.stream.Flowable;
import com.alogic.xscript.util.LogicletConstants;


/**
 * 日志信息
 * @author duanyy
 *
 */
public class LogInfo implements Flowable,LogicletConstants {
	/**
	 * 活动
	 */
	protected String activity = DFT_ACTIVITY;

	/**
	 * 日志的信息
	 */
	protected String message = "";
	
	/**
	 * 日志级别(warn,error,info)
	 */
	protected String level = LOG_INFO;

	@Override
	public String id(){
		return activity;
	}	
	
	@Override
	public boolean isAsync(){
		return true;
	}

	public LogInfo(String activity,String message,String level){
		this.activity = activity;
		this.message = message;
		this.level = level;
	}
	
	public LogInfo(String activity,String message){
		this(activity,message,"info");
	}
	
	public LogInfo message(String message){
		this.message = message;
		return this;
	}
	
	public LogInfo activity(String activity){
		this.activity = activity;
		return this;
	}
	
	public LogInfo level(String level){
		this.level = level;
		return this;
	}
	
	public String activity(){
		return activity;
	}
	
	public String message(){
		return message;
	}
	
	public String level(){
		return level;
	}
	
	public String getValue(String varName, Object context, String defaultValue) {
		if (varName.equals("msg")){
			return message;
		}
		if (varName.equals("level")){
			return level;
		}
		if (varName.equals("activity")){
			return activity;
		}
		return defaultValue;
	}

	public Object getContext(String varName) {
		return this;
	}

	@Override
	public String getRawValue(String varName, Object context, String dftValue) {
		return getValue(varName,context,dftValue);
	}		
	
	public String getStatsDimesion() {
		return level;
	}

}
